package com.spq.paramsverify.service;

import com.spq.paramsverify.dao.StudentMapper;
import com.spq.paramsverify.entity.Student;
import com.spq.paramsverify.entity.StudentExample;
import com.spq.paramsverify.req.AddOrEditStudentReq;
import com.spq.paramsverify.resp.StudentResp;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description TODO
 * @Author gongjianpeng
 * @Date 2022/1/19
 */
@Service
public class StudentBll implements StudentService {

    @Resource
    private StudentMapper studentMapperExt;

    @Override
    public boolean addStudent(AddOrEditStudentReq req) {
        Student student = new Student();
        BeanUtils.copyProperties(req, student);
        int i = studentMapperExt.insertSelective(student);
        return i > 0;
    }

    @Override
    public StudentResp getStudent(Long id) {
        StudentResp studentResp = new StudentResp();
        Student student = studentMapperExt.selectByPrimaryKey(id);
        BeanUtils.copyProperties(student, studentResp);
        return studentResp;
    }

    @Override
    public boolean updateStudent(AddOrEditStudentReq req) {
        Student student = new Student();
        BeanUtils.copyProperties(req, student);
        int result = studentMapperExt.updateByPrimaryKeySelective(student);
        return result > 0;
    }
}
